const express = require('express')

const router = express.Router()

//导入token中间件jwt
const jwts = require('../dao/jwt')

const chatRouter = require('../router_handle/chat')

//分页获取聊天页面消息记录
router.get('/getmsg', (req, res) => {
    let token = req.headers.token
    let { verifytoken } = jwts.verifyToken(token)
    if (verifytoken == 1) { //token验证正确 
        let data = req.query
        chatRouter.getmsg(data, res)
    } else {
        console.log('token验证失败');
        res.sendMsg('token验证失败', 304)
    }
})

//分页获取群聊天数据
router.get('/getgroupmsg', (req, res) => {
    let token = req.headers.token
    let { verifytoken } = jwts.verifyToken(token)
    if (verifytoken == 1) { //token验证正确 
        let data = req.query
        chatRouter.getGroupMsg(data, res)
    } else {
        console.log('token验证失败');
        res.sendMsg('token验证失败', 304)
    }
})


module.exports = router